from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver import ActionChains
d = webdriver.Chrome()
d.get('https://www.baidu.com')
a = d.find_element(By.CSS_SELECTOR, '[id="s-usersetting-top"]')
ActionChains(d).move_to_element(a).perform()
b = d.find_element(By.CSS_SELECTOR, '[class="set"]')
b.click()
time.sleep(1)
# 点击保存设置
save_link = d.find_element(By.LINK_TEXT, '保存设置')
save_link.click()
time.sleep(1)
# 警告框处理  switch_to.alert
msg = d.switch_to.alert.text # 获取警告框的文本
# d.switch_to.alert.dismiss() # 关闭警告框
d.switch_to.alert.accept() # 确认警告框
print(msg)

